package com.zhiyou100.action;

import com.zhiyou100.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author yang
 * @className TeacherAction
 * @packageName com.zhiyou100.action
 * @Description TODO 老师 action
 * @date 2020-08-25 19:31
 */
@Controller
@RequestMapping("/teacher")
public class TeacherAction {
    private TeacherService teacherService;

    @Autowired
    public void setTeacherService(TeacherService teacherService) {
        this.teacherService = teacherService;
    }

    @RequestMapping("/login.action")
    public String getAll(Model model, Integer tid, String tpwd, HttpSession session) {
        System.out.println(tid+" : "+tpwd);
        final boolean login = teacherService.login(tid, tpwd);

        if (login){
            // 登陆成功，转发到 成功页面
            //model.addAttribute("teacher",teacherService.getOneByTid(tid));
            session.setAttribute("teacher",teacherService.getOneByTid(tid));
            return "jsp/success";
        }else {
            model.addAttribute("message","登陆失败，少侠请重新来过");
            return "index";
        }
    }

}
